package br.com.tiaspider.spiders.task;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimerTask;

import br.com.tiaspider.spiders.TiaSpider;

public class TiaSpiderTimerTask extends TimerTask{
	
	private static final String DATE_FORMAT = "dd/MM/yyyy hh:mm:ss";
	private TiaSpider spider;
	
	public TiaSpiderTimerTask(TiaSpider spider){
		setSpider(spider);
	}
	
	@Override
	public void run(){
		System.out.println( "###############################################################################" );
		Calendar cal = Calendar.getInstance();
		String info = getSpider().responseToPrettyString( getSpider().getPageContent() );
		System.out.println( info );
		System.out.println( "Ultima leitura: " + ( new SimpleDateFormat( DATE_FORMAT ).format(  cal.getTime() ) ));
	}

	private void setSpider(TiaSpider spider) {
		this.spider = spider;
	}

	public TiaSpider getSpider() {
		return this.spider;
	}
}
